var avatarUp0, avatarUp1, avatarUp2, avatarUp3, avatarUp4, avatarUp5,
    avatarUp6, avatarUp7, avatarUp8 = "";

function iconTypeChange() {
    avatarUp0 = new $IconUpload("avatar0");
    avatarUp0.initIcon();
    avatarUp1 = new $IconUpload("avatar1");
    avatarUp1.initIcon();
    avatarUp2 = new $IconUpload("avatar2");
    avatarUp2.initIcon();
    avatarUp3 = new $IconUpload("avatar3");
    avatarUp3.initIcon();
    avatarUp4 = new $IconUpload("avatar4");
    avatarUp4.initIcon();
    avatarUp5 = new $IconUpload("avatar5");
    avatarUp5.initIcon();
    avatarUp6 = new $IconUpload("avatar6");
    avatarUp6.initIcon();
    avatarUp7 = new $IconUpload("avatar7");
    avatarUp7.initIcon();
    avatarUp8 = new $IconUpload("avatar8");
    avatarUp8.initIcon();
}

$(function () {
    iconTypeChange();
});

function firstClose() {
    parent.layer.close(parent.layer.getFrameIndex(window.name));
}

function storagePeriodontal() {
    var reservationsId=window.parent.document.getElementById("reservationsId").value;
    var num=document.getElementById("num").value;
    var customerName=$("#customerName",parent.document).val();
    var doctor = $("#doctor").val();
    var nurse = $("#nurse").val();
    if(doctor==null || doctor=="" || doctor==undefined){
        alert("请选择医生");
        return false;
    }
    if(nurse==null || nurse=="" || nurse==undefined){
        alert("请输入护士");
        return false;
    }
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/storagePeriodontal",
        type: "post",
        data: {
            "num": num,
            "reservationsId": reservationsId,
            "customerName": customerName,
            "doctor": doctor,
            "nurse": nurse
        },
        success: function (data) {
            Feng.success('操作成功!');
            window.parent.uploadPeriodontalTable.table.refresh();
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }
    })
}

function subPeriodontal() {
    if($("#avatar0PreId").children().length <= 0 || $("#avatar1PreId").children().length <= 0 || $("#avatar2PreId").children().length <= 0
        || $("#avatar3PreId").children().length <= 0 || $("#avatar4PreId").children().length <= 0 || $("#avatar5PreId").children().length <= 0
        || $("#avatar6PreId").children().length <= 0 || $("#avatar7PreId").children().length <= 0 || $("#avatar8PreId").children().length <= 0){
        Feng.error("请补全照片！");
        return false;
    }
    var reservationsId=window.parent.document.getElementById("reservationsId").value;
    var num=document.getElementById("num").value;
    var customerName=$("#customerName",parent.document).val();
    var doctor = $("#doctor").val();
    var nurse = $("#nurse").val();
    if(doctor==null || doctor=="" || doctor==undefined){
        alert("请选择医生");
        return false;
    }
    if(nurse==null || nurse=="" || nurse==undefined){
        alert("请输入护士");
        return false;
    }
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/subPeriodontal",
        type: "post",
        data: {
            "reservationsId": reservationsId,
            "num": num,
            "customerName": customerName,
            "doctor": doctor,
            "nurse": nurse
        },
        success: function (data) {
            Feng.success('操作成功!');
            window.parent.uploadPeriodontalTable.table.refresh();
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        }
    })
}

$('#avatar0PreId,#avatar1PreId,#avatar2PreId,#avatar3PreId,#avatar4PreId,#avatar5PreId,#avatar6PreId,#avatar7PreId,#avatar8PreId').on('click', '.cp_img_delete', function (e) {
    e.stopPropagation();
    var that = this;
    var id = $(that).parent().attr("id");
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/deletePeriodontalImgs",
        type: "post",
        data: {"id": id},
        success: function (data) {
            $(that).parent().parent().siblings().css({'pointer-events': 'auto', 'cursor': 'pointer', 'background': 'white'});
            $(that).parent().remove();
            Feng.success("删除成功！");
        },
        error: function (data) {
            alert("删除失败！");
        }
    });
});